<?php
/**
 * @version $Id: default.php 25 2009-06-29 19:42:20Z der.el.kuku $
 * @package    JClassDocumentor
 * @subpackage _ECR_SUBPACKAGE_
 * @author     EasyJoomla {@link http://www.easy-joomla.org Easy-Joomla.org}
 * @author     Nikolai Plath {@link http://www.easy-joomla.org}
 * @author     Created on 23-Jun-2009
 */

//--No direct access
defined('_JEXEC') or die('=;)');

$baseDir = JPATH_ROOT.DS.'libraries'.DS.'joomla';
$baseFolders = JFolder::folders($baseDir);

$folder_name = JRequest::getVar('jdoc_folder');
$folder_name_sub = JRequest::getVar('jdoc_subfolder');
$folder_name_sub_sub = JRequest::getVar('jdoc_sub_subfolder');
$jdoc_file =JRequest::getVar('jdoc_file');
$output_format =JRequest::getVar('output_format', 'wikinafu');

$backLink = 'index.php?option=com_jclassdocumentor';
$backLink .=($folder_name) ? '&jdoc_folder='.$folder_name : '';
$backLink .=($folder_name_sub) ? '&jdoc_subfolder='.$folder_name_sub : '';
$backLink .=($folder_name_sub_sub) ? '&jdoc_sub_subfolder='.$folder_name_sub_sub : '';
$backLink .=($jdoc_file) ? '&jdoc_file='.$jdoc_file : '';;
$backLink .=($output_format) ? '&output_format='.$output_format : '';
$backLink .= '&tmpl=component';

if( $folder_name && ! in_array($folder_name, $baseFolders))
{
	echo 'Invalid folder';
	return;
}
$subFolders =( $folder_name ) ? JFolder::folders($baseDir.DS.$folder_name) : array();
if( $folder_name_sub && ! in_array($folder_name_sub, $subFolders))
{
	$folder_name_sub = '';
}
$subSubFolders =( $folder_name_sub ) ? JFolder::folders($baseDir.DS.$folder_name.DS.$folder_name_sub) : array();
if( $folder_name_sub_sub && ! in_array($folder_name_sub_sub, $subSubFolders))
{
	$folder_name_sub_sub = '';
}
if( JFolder::exists($baseDir.DS.$folder_name.DS.$folder_name_sub.DS.$folder_name_sub_sub))
{
	$classFiles = JFolder::files($baseDir.DS.$folder_name.DS.$folder_name_sub.DS.$folder_name_sub_sub, '\.php$');//, true, true);
}
?>

<div style="border: 2px dashed grey; padding: 1em;">
<div style="float: right"><a href="<?php echo JRoute::_($backLink); ?>">perma</a></div>
<div style="font-size: 1.8em; font-weight: bold;">
	JFrameworkDocumentor <span style="color: grey;">documenting</span> Joomla! <span style="color: blue;"><?php echo JVERSION; ?></span>
</div>

<form action="index.php" method="post" name="jdocForm" id="form-jdocForm">
<div class="inner_form">
<tt>/libraries/joomla/</tt>
<table width="100%">

<tr valign="top">

<td width="5%">Subpackage<br />
<select name="jdoc_folder" size="5" onchange="document.jdocForm.submit();">
<option value="">/</option>

<?php
foreach ($baseFolders as $folder)
{
	$selected =( $folder == $folder_name ) ? ' selected="selected"' : '';
	echo '<option value="'.$folder.'"'.$selected.'>'.$folder.'</option>'.NL;
}//foreach
?>

</select>
</td>

<?php
if( count($subFolders) )
{
	?>
	<td width="5%">
	<br />
	<select name="jdoc_subfolder"  size="5" onchange="document.jdocForm.submit();">
	<option value="" selected="selected">/</option>
	<?php
	foreach ($subFolders as $folder)
	{
		$selected =( $folder == $folder_name_sub ) ? ' selected="selected"' : '';
		echo '<option value="'.$folder.'"'.$selected.'>'.$folder.'</option>';
	}//foreach
	?>

	</select>
	</td>
<?php
}

if( count($subSubFolders) )
{
	?>

	<td width="5%"><br />
	<select name="jdoc_sub_subfolder"  size="5" onchange="document.jdocForm.submit();">
	<option value="" selected="selected">/</option>

	<?php
	foreach ($subSubFolders as $folder)
	{
		$selected =( $folder == $folder_name_sub_sub ) ? ' selected="selected"' : '';
		echo '<option value="'.$folder.'"'.$selected.'>'.$folder.'</option>'.NL;
	}//foreach

	?>
	</select>
	</td>
<?php
}
?>

<td width="5%"><span style="color: orange; font-weight: bold;">Class file</span><br />
<select name="jdoc_file"  size="5" onchange="document.jdocForm.submit();">
<option value="">Select...</option>
<?php
foreach ($classFiles as $file)
{
	$selected =( $file == $jdoc_file ) ? ' selected="selected"' : '';
	echo '<option value="'.$file.'"'.$selected.'>'.$file.'</option>'.NL;
}//foreach
?>
</select>
</td>

<td style="text-align: right; padding-right: 2em;"><?php echo JHTML::_('image', JURI::root().'images/joomla_logo_black.jpg', 'Joomla! Logo'); ?></td>

<td width="5%">Output format<br />
<select name="output_format" size="5" onchange="document.jdocForm.submit();">
<option value="html" <?php echo ( $output_format == 'html' ) ? ' selected="selected"' : ''; ?>>HTML</option>
<option value="wikinafu" <?php echo ( $output_format == 'wikinafu' ) ? ' selected="selected"' : ''; ?>>wiki.joomla-nafu.de</option>
<option value="docswiki" <?php echo ( $output_format == 'docswiki' ) ? ' selected="selected"' : ''; ?>>docs.joomla.org</option>
</select>
</td>

</tr>
</table>

<noscript>
<input type="submit" name="Submit" class="button" value="Refresh" />
<br />
<strong style="color: blue;">TIP: Activate Javascript to have some more FUN</strong> <tt>=;)</tt>
</noscript>

<input type="hidden" name="option" value="com_jclassdocumentor" />
<input type="hidden" name="view" value="jclassdocumentor" />

<input type="hidden" name="tmpl" value="component" />

</div>
</form>

</div>

<div style="padding: 0.7em; border-left: 2px dashed grey; border-right: 2px dashed grey;">
<?php
if( $jdoc_file && in_array($jdoc_file, $classFiles))
{
	JLoader::import('helpers.reflector', JPATH_COMPONENT);

	echo EasyReflector::reflect($baseDir, $folder_name, $folder_name_sub, $folder_name_sub_sub, $jdoc_file, $output_format, true);
}
else
{
	echo '<h1 style="text-align: center">What\'s your Class, (wo)man ?<br /><br /><tt>=;)</tt></h1>'.NL;
}
?>
</div>

<?php
$i = JHTML::_('image', JURI::root().'components/com_jclassdocumentor/assets/images/easy-joomla-favicon.ico', 'Easy-Joomla.org');
echo '<div style="text-align: center; border: 2px dashed grey; padding: 0.3em;">';
echo 'Developed 2009 by '.$i.'<a href="http://easy-joomla.org">Easy-Joomla</a> for <a href="http://wiki.joomla-nafu.de">Wiki.Joomla-Nafu.de</a>';
echo '</div>';
